package com.guaju.yueshangLife.activity.setting;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.support.annotation.NonNull;
import android.os.Bundle;
import android.view.View;

import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.guaju.yueshangLife.R;
import com.guaju.yueshangLife.base.BaseActivity;
import com.guaju.yueshangLife.databinding.ActivitySettingBinding;
import com.guaju.yueshangLife.net.ApiClient;
import com.guaju.yueshangLife.net.ApiEntity;
import com.guaju.yueshangLife.utils.PreferenceUtil;

public class SettingActivity extends BaseActivity {

    private ActivitySettingBinding binding;
    private MaterialDialog logoutDialog;

    @Override
    protected void loadViewLayout() {
        binding = DataBindingUtil.setContentView(this,R.layout.activity_setting);
    }

    @Override
    protected void bindViews() {

    }

    @Override
    protected void processLogic(Bundle savedInstanceState) {

    }

    @Override
    protected void setListener() {
        binding.tvLogout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                logoutDialog = new MaterialDialog.Builder(SettingActivity.this)
                        .title("确认退出")
                        .content("退出后将无法完成购物，您确定要退出账号？")
                        .negativeText("确认离开")
                        .negativeColor(getResources().getColor(R.color.c_gray1))
                        .positiveText("取消")
                        .positiveColor(getResources().getColor(R.color.colorPrimary))
                        .onPositive(new MaterialDialog.SingleButtonCallback() {
                            @Override
                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                dialog.dismiss();
                            }
                        })
                        .onNegative(new MaterialDialog.SingleButtonCallback() {
                            @Override
                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                ApiEntity.logout();
                                PreferenceUtil.setIsLogin(false);
                                PreferenceUtil.setToken("");
                                PreferenceUtil.setAvatar("");
                                PreferenceUtil.setFphone("");
                                PreferenceUtil.setNickName("");
                                dialog.dismiss();
                                SettingActivity.this.finish();
                            }
                        })
                        .build();
                logoutDialog.show();
            }
        });

        binding.lineInfo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                Intent intent = new Intent(SettingActivity.this, MyInfoActivity.class);
                startActivity(intent);
            }
        });
        binding.lineSafe.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(SettingActivity.this, AcountSafeActivity.class);
                startActivity(intent);

            }
        });
    }
}
